import { BaseMsgHandler } from "../../framework/BaseMsgHandler";
import { DebugHost } from "../DebugHost";
import { EMessageC2S } from "../../../common/EMessageC2S";
import { ClientMsg } from "../../framework/common/ClientMsg";
import { DebugClient } from "../DebugClient";
import { EClientState } from "../../framework/common/EClientState";
import { EClientType } from "../../../common/EClientType";
import { EMessageS2C } from "../../../common/EMessageS2C";

export class HandleC1003 extends BaseMsgHandler<DebugHost> {

    msgId: number = EMessageC2S.ConnectClient;

    HandleMsg(msg: ClientMsg) {
        let client = msg.client as DebugClient;
        if (client.state != EClientState.Idle) {
            client.SendError('状态错误');
            return;
        }
        if (client.type != EClientType.Debugger) {
            client.SendError('类型错误');
            return;
        }
        let connectId = msg.transData.data as number;
        let findClient = this.owner.SearchClient(connectId);
        if (findClient == null) {
            client.SendMsg(EMessageS2C.ConnectClient, false);
            return;
        }
        if (this.owner.ConnectPair(findClient, client)) {
            client.SendMsg(EMessageS2C.ConnectClient, true);
        } else {
            client.SendMsg(EMessageS2C.ConnectClient, false);
        }

    }

}